<?php

class ValidatorOrganisationalEntityCanHaveChildren extends sfValidatorBase {
	
	protected function doClean($value) {
		$record = OrganisationalEntityTable::getInstance()->findOneById ( $value );
		
		if (! $record) {
			throw new sfValidatorError($this, 'invalid', array('value' => $value));
		}
		
		if(!$record->canHaveChildren()) {
			throw new sfValidatorError($this, 'invalid', array('value' => $value));
		}
		
		return $value;
	}
}